<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('【请填写功能名称】列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:template:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:template:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:template:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:template:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:template:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:template:remove')}]];
        var prefix = ctx + "base/job/template";
        function taskAllocation(id) {
            $.modal.openTab("模板任务分配",ctx+"base/job/template/task?idTemplate="+id)
        }
        function formatLongDate(longDate) {
            debugger;
            longDate = Number(longDate);
            if(longDate==0) {
                return '';
            }
            const date = new Date(longDate); // 将长型日期转换为Date对象
            const year = date.getFullYear(); // 获取年份
            const month = (date.getMonth() + 1).toString().padStart(2, '0'); // 获取月份并补零
            const day = date.getDate().toString().padStart(2, '0'); // 获取日期并补零
            const hours = date.getHours().toString().padStart(2, '0'); // 获取小时并补零
            const minutes = date.getMinutes().toString().padStart(2, '0'); // 获取分钟并补零
            const seconds = date.getSeconds().toString().padStart(2, '0'); // 获取秒钟并补零

            return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; // 拼接字符串返回
        }
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "定时管理",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '主键',
                    visible: false
                },
                {
                    field: 'jobDesc',
                    title: '任务描述'
                },
                {
                    field: 'jobGroup',
                    title: '执行器'
                },
                {
                    field: 'jobCron',
                    title: 'CRON'
                },
                {
                    field: 'executorBlockStrategy',
                    title: '阻塞处理策略'
                },
                {
                    field: 'executorRouteStrategy',
                    title: '执行器路由策略'
                },
                {
                    field: 'glueType',
                    title: 'GLUE类型'
                },
                {
                    field: 'triggerStatus',
                    title: '调度状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        if (row.triggerStatus == 0) {
                            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.userId + '\')"></i> ';
                        } else {
                            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.userId + '\')"></i> ';
                        }
                    }
                },
                {
                    field: 'triggerLastTime',
                    title: '上次调度时间',
                    formatter: function(value, row, index) {
                        return formatLongDate(row.triggerLastTime);
                    }
                },
                {
                    field: 'triggerNextTime',
                    title: '下次调度时间',
                    formatter: function(value, row, index) {
                        return formatLongDate(row.triggerNextTime);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        actions.push('<a class="btn btn-info btn-xs " href="javascript:void(0)" onclick="taskAllocation(\'' + row.id + '\')"><i class="fa fa-edit"></i>分配</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
    </script>
</body>
</html>